﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;


public partial class Bidder_TraBidPlanList : System.Web.UI.Page, HZ.MBSM.BLL.TraDes
{
    public string _strProjectId = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        _strProjectId = SysFun.IsSQL(SysFun.ToTrim(Request.QueryString["ProjectId"]));

        if (HZ.MBSM.BLL.Login.CheckAssert(this.UseAccountType))
        {
            if (_strProjectId != "")
            {
                if (!IsPostBack)
                {
                    DrBuyStatus.Items.Add("全部");
                    DrBuyStatus.Items.Add("未确认送货");
                    DrBuyStatus.Items.Add("已确认送货");
                    
                }
                DrBuyStatus.Visible = false;
                showGridView();
            }
        }
    }

    public void showGridView()
    {
        string strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "PurchasePlan_VIEW";                                      //要查询的表明
        dbPage.Key = "BuyPlanId";                                          //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = "hospitalname,BuyPlanId,PlanName,StartTime,EndTime,BuildTime,case  when memo1='1' then '已确认送货' else '未确认送货'   end BuyStatus";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 20;                                                    //没有显示记录条数   
        dbPage.OrderBy = "BuyPlanId";                  //排序字段
        dbPage.OrderByIsDesc = true;
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        DlAttorney.DataSource = dr;
        DlAttorney.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键
    }
    /// <summary>
    /// 生成查询条件
    /// </summary>
    /// <returns></returns>
    public string fctConditions()
    {
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        string _strAccountId_PS = SysFun.ToTrim(_Account.AccountId);
        //此处在数据量增大后,要修改
        string _strTemp = " projectid=" + _strProjectId + " and BuyStatus='2' and  BuyPlanId in (select distinct BuyPlanId from BuyPlanGoods where AccountId_PS=" + _strAccountId_PS + ") and";


        //采购单名称
        string _strPlanName = txtPlanName.Text;
        if (_strPlanName != "")
        {
            _strTemp += "  PlanName like'%" + _strPlanName + "%' and";
        }
        //采购单状态
        string _strBuyStatus = DrBuyStatus.SelectedValue.ToString();
        switch (_strBuyStatus)
        {
            case "全部":
                break;
            case "未确认送货":
                _strTemp += " (memo1=0 or memo1 is null) and";
                break;
            case "已确认送货":
                _strTemp += " memo1=1 and";
                break;

        }

        //开始时间
        string _strStartTime = txtStartTime.Text.ToString();
        if (_strStartTime != "")
        {
            _strTemp += " StartTime>='" + _strStartTime + "' and";
        }

        //结束时间
        string _strEndTime = txtEndTime.Text.ToString();
        if (_strEndTime != "")
        {
            _strTemp += " EndTime <='" + _strEndTime + "' and";
        }
        if (_strTemp != "")
        {
            _strTemp = "  " + _strTemp.Substring(0, _strTemp.Length - 3);
        }
        return _strTemp;
    }


    #region TraDes 成员

    public string Name
    {
        get { return "采购单管理"; }
    }

    public string Describe
    {
        get { return ""; }
    }

    public string ParentName
    {
        get { return "配送管理"; }
    }

    public System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> UseAccountType
    {
        get
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCompany);
            return _AccountType;
        }
    }

    #endregion
    
    
}
